package alvarodelrosal.chat.client.gui;

import alvarodelrosal.chat.client.chataction.infraestructuraremota.AllUsers;
import alvarodelrosal.chat.client.chataction.remote.ChatDeleteUser;
import alvarodelrosal.chat.client.modelo.ChatUser;
import java.util.List;

public class AdministrarUsuarios extends javax.swing.JFrame {

    public AdministrarUsuarios() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();

        setTitle("Administración de usuarios");

        jList1.setModel(new javax.swing.AbstractListModel() {
            List<ChatUser> users = AllUsers.getAllUsers();
            public int getSize() { return users.size(); }
            public Object getElementAt(int i) { return users.get(i); }
        });
        jScrollPane1.setViewportView(jList1);

        jButton1.setText("Borrar usuario");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .add(0, 0, Short.MAX_VALUE)
                .add(jButton1))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ChatUser user = (ChatUser) jList1.getSelectedValue();
        ChatDeleteUser deleteUser = new ChatDeleteUser();
        List<String> prepareParameters = deleteUser.prepareParameters(user.getId());
        deleteUser.doAction(prepareParameters);
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
